// pages/zhanghu/zhanghu.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userInfo: {},
    img: "",
    name: "",
    userId:"",
    // 存储金额
    jine:"0",
    number: ["50", "100", "200"],
    number1: ["500", "800", "1000"],
    hiddenName: true,
    showAdd:true,
    money:0,
    shuru:"",
    
  },

  chongzhi: function () {
    wx.navigateTo({
      url: '../zhanghu/chongzhijl/chongzhijl',
    })
  },
  xiaofei: function () {
    wx.navigateTo({
      url: '../zhanghu/xiaofeijl/xiaofeijl',
    })
  },
  shouhuo: function () {
    wx.navigateTo({
      url: '../zhanghu/shouhuodz/shouhuodz',
    })
  },
  bindViewTap:function(e){
  wx.request({
    url: 'http://123.206.228.246:50080/wxone/user/userInfo',
    method: "POST",
    data: {
      name: e.detail.userInfo.nickName,
      headImage: e.detail.userInfo.avatarUrl,
    },
    header: {
      'content-type': 'application/json' // 默认值
    },
  })
    success: (res) => {
      console.log(res)
      this.setData({
        name:data.data.name,
        headImage:data.data.headImage
      })

    }
  },
//输入框失去焦点
  input_sq:function(res){
   var that=this
  that.setData({
    money:parseInt(res.detail.value)
  })
  },
  //事件处理函数
  click: function (e) {
    this.setData({
      hasUserInfo: true
    })
  },
  // 数据叠加
  queren: function (e) { 
    console.log(e)
    console.log(",,,,,,,,")
   wx.request({
     url: 'http://123.206.228.246:50080/wxone/recharge/record',
     method:"POST",
     data:{
       userId: app.globalData.userId,
       money:this.data.money
     },
     header: {
       'content-type': 'application/json'  // 默认值
     },
     success: (res) => {
       console.log(".......")
       console.log(res)
     }
   })
   if(this.data.shuru<=0){
     wx.showModal({
       title: '充值失败',
       content: '金额不能小于0',
     })
   }else{
     var a = this.data.jine;
     var b = this.data.shuru;
     var c=this.data.money;
     this.setData({
       hasUserInfo: true,
       shuru: "0",
       money: Number(a) + Number(b)+Number(c),
     })
     console.log(this.data.money)
   }
  },

  wushi: function (e) {
    switch (e.target.id) {
      case "0":
        this.setData({
          shuru: "50"
        });
        break;
      case "1":
        this.setData({
          shuru: "100"
        });
        break;
      case "2":
        this.setData({
          shuru: "200"
        });
    }
    console.log(this.data.shuru)
  },
  wubai: function (e) {

    switch (e.target.id) {
      case "0":
        this.setData({
          shuru: "500"
        });

        break;
      case "1":
        this.setData({
          shuru: "800"
        });
        break;
      case "2":
        this.setData({
          shuru: "1000"
        });
    }
    console.log(this.data.shuru)
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  tankuang: function (e) {
    this.setData({
      hasUserInfo: !this.data.hasUserInfo
    })

  var that=this;
  console.log(e)
  that.setData({
    name:e.nickName,
    img:e.avatarUrl,
    userId:e.userId
  })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})